#ifndef WF_ARC_H
#define WF_ARC_H

#include <btime.h>
#include <iarc.h>
#include <iedgedata.h>

#include <QtCore/QObject>
#include <QtCore/QPointer>

using namespace core;
using namespace net;

namespace net
{
class IMultiset;
}

namespace wfnet
{
class Expression;
class Place;
class Transition;
class WfNet;

class Arc : public QObject, /*implements*/public IArc,
    public IEdgeData
{
    Q_OBJECT

    enum ConnectionType
    {
        PlaceToTransition,
        TransitionToPlace
    };

public:
    ~Arc();

    // IIdentifiable
    nid getId() const;

    // IArc
    IExpression* getExpression() const;
    core::BasicTime getDelay() const;

    void setExpression(IExpression* expression);
    void setDelay(const core::BasicTime& time);

    Place* getPlace() const;
    Transition* getTransition() const;
    ConnectionType getConnectionType() const;

    // IEdgeData
    void registerEdge(Edge* edge);
    const Edge* const edge() const;

    IMultiset* eval(core::BasicTime globalClock = 0) const;

protected:
    Arc(WfNet* parent, nid id, Place* place,
        Transition* transition, ConnectionType type, BasicTime delay = 0);

private:
    friend class WfNet;

    Edge* m_edge; // guarded pointer
    nid m_id;
    QPointer<Place> m_place;
    QPointer<Transition> m_transition;
    QPointer<Expression> m_expression;
    ConnectionType m_connectionType;
    BasicTime m_delay;
};

} // namespace wfnet

#endif
